import { ref, computed,reactive } from 'vue'
import { defineStore } from 'pinia'

export const ClassStore = defineStore('ClassStore', () => {


  
  // 搜索
  const searchInfo=reactive(
    {
    class_name: "",//课程名称
    is_shelves: null,//是否上架
    is_compilation: null,//是否合集
    }
  )
  // 表格
const tableData = <any>reactive([

]);
const Data = <any>reactive([

]);

const oneClass=<any>reactive([{className:""}]);




// 添加视频
const video = reactive<any>([
  {
  video_name: "",
  id: "",
  video_duration: "", //视频时长
  video: "", //视频地址
}
]);

const exam=reactive({
  exam_name:"",
  exam_id:null
})

// 获取全部---收费
function getAll(classs:any){
  tableData.splice(0,tableData.length);
  classs.forEach((item:any) => {
    
    tableData.push(item);
  })
}
//免费
function getFreeAll(classs:any){
  Data.splice(0,Data.length);
  classs.forEach((item:any) => {
    
    Data.push(item);
  })
}
// 按id获取某个课程
function getOne(classs:any){
  oneClass.splice(0,1,classs);
}

// 按id删除某个课程
function delOne(id:any){
  tableData.forEach((item:any,index:number) => {
    if(item.id==id){
      tableData.splice(index,1);
    }
  })
}

// 查询课程下的所有视频
function getVideo(vs:any){
  video.splice(0,video.length);
  vs.forEach((item:any) => {
    video.push(item);
  })
}





  return { tableData,oneClass, searchInfo, video,exam,getAll ,getOne,delOne,
  getVideo,Data,getFreeAll}
})
